package com.adam.example.newssearches8_2_0.po;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.time.format.DateTimeFormatter;

@Data
public class NewsESO {

    private long id;
    private String title;
    @JsonProperty("key_word")
    private String keyword;
    private String content;
    private String url;
    private int reply;
    private String source;
    private String postdate;

    public static NewsESO of(NewsPO newsPO) {
        NewsESO newsESO = new NewsESO();
        newsESO.setId(newsPO.getId());
        newsESO.setTitle(newsPO.getTitle());
        newsESO.setKeyword(newsPO.getKeyword());
        newsESO.setContent(newsPO.getContent());
        newsESO.setUrl(newsPO.getUrl());
        newsESO.setReply(newsPO.getReply());
        newsESO.setSource(newsPO.getSource());
        newsESO.setPostdate(newsPO.getPostdate().toLocalDateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        return newsESO;
    }

}
